package TP3.ejercicio2;

import TP2.sorters.AbstractSorter;
import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

public class HSorter extends AbstractSorter {

    int gap;

    public HSorter(){
        this(SorterType.H);
        gap = 11;
    }

    protected HSorter(final SorterType type){
        super(type);
    }

    public void setGap(int a){
        gap = a;
    }

    public <T> void sort(Comparator<T> comparator, List<T> list){
        sort(comparator, list, gap);
    }

    protected <T> void sort(Comparator<T> comparator, List<T> list, int gap){
        for (int i = gap; i < list.size(); i = i + gap) {
            if (gap < list.size() && greater(comparator, list, i - gap, i)) {
                swap(list, i - gap, i);

            }
        }
    }

}
